package admin.service;



import admin.repository.PropagandaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import common.model.Propaganda;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PropagandaService {

    @Autowired
    private PropagandaRepository propagandaRepository;

    public void deletePropaganda(Long id) {
        propagandaRepository.deleteById(id);
    }

    public List<Propaganda> findPropaganda(Date date, String lawyerName, Boolean approved) {
        return propagandaRepository.findByDateAndLawyerNameAndApproved(date, lawyerName, approved);
    }

    public void approvePropaganda(Long id) {
        Propaganda propaganda = propagandaRepository.findById(id).orElseThrow(() -> new RuntimeException("Propaganda not found"));
        propaganda.setApproved(true);
        propagandaRepository.save(propaganda);
    }
}
